
class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        if (nums.size() < 2)
            return;
        int index = nums.size() - 2;
        while (index >= 0 && nums[index] >= nums[index + 1])
        {
            --index;
        }
        if (index >= 0)
        {
            for (int i = nums.size() - 1;i > index;--i)
            {
                if (nums[i] > nums[index])
                {
                    std::swap(nums[i], nums[index]);
                    break;
                }
            }
        }
        std::reverse(nums.begin() + index + 1, nums.end());
        return;
    }
};